package com.atguigu.lease.admin.controller.apartment;

import com.atguigu.lease.admin.service.PaymentTypeService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.PaymentType;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/payment")
@Tag(name = "支付方式管理模块")
public class PaymentInfoController {
    @Autowired
    PaymentTypeService paymentTypeService;
    //    /list      ?k=v&k2=v2
    @GetMapping("/list")
    @Operation(summary = "1、查询所有支付方式")
    public Result<List<PaymentType>> list(){
        return Result.ok(paymentTypeService.list());
    }
    ///admin/payment/saveOrUpdate
    @PostMapping("/saveOrUpdate")
    @Operation(summary = "2、新增或更新支付方式")
    public Result saveOrUpdate(@RequestBody PaymentType paymentType){
//        paymentType.setCreateTime(new Date());
//        paymentType.setUpdateTime(new Date());
        //mybatisplus的自动填充
        //  mp在新增或者更新时 可以按照配置 自动给有些属性设置属性值
        //  createTime: 新增数据时设置
        //  updateTime: 新增数据、更新数据时都设置
        return Result.ok(paymentTypeService.saveOrUpdate(paymentType));
    }
    ///admin/payment/deleteById?id=14
    @Operation(summary = "3、根据id删除支付方式")
    @DeleteMapping("/deleteById")
    public Result deleteById(@Parameter(description = "主键值" , in = ParameterIn.QUERY,required = true)
                                 @RequestParam("id") Integer id){
        return Result.ok(paymentTypeService.removeById(id));
    }











    @GetMapping("/page/{pageNum}/{pageSize}")
    @Operation(summary = "查询支付方式分页数据")
    public Result<Page<PaymentType>> page(
            @Parameter(description = "页码",in = ParameterIn.PATH) @PathVariable("pageNum") long pageNum,
            @Parameter(description = "每页记录数",in = ParameterIn.PATH) @PathVariable("pageSize") long pageSize

    ){
        return Result.ok(paymentTypeService.page(new Page<PaymentType>(pageNum,pageSize)));
    }
}
